package com.dehui.traders.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.bean.OptionalStockBean;
import com.dehui.traders.widgets.BaseViewHolder;
import com.dehui.traders.widgets.CommonAdapter;

import java.util.List;

/**
 * Created by hqq on 18.4.18.
 */

public class OptionalStockAdapter extends CommonAdapter<OptionalStockBean>{

    private OnOptionalStockAdapterListener listener;

    public OptionalStockAdapter(Context context, List<OptionalStockBean> mDatas, int itemLayoutId) {
        super(context, mDatas, itemLayoutId);
    }

    public void setListener(OnOptionalStockAdapterListener listener){
        this.listener = listener;
    }

    @Override
    public void convert(BaseViewHolder helper, OptionalStockBean item, int position) {
        TextView tvName = helper.getView(R.id.tv_name);
        TextView tvCode = helper.getView(R.id.tv_code);
        ImageView ivAdd = helper.getView(R.id.iv_add);
        TextView tvAdd = helper.getView(R.id.tv_add);

        tvName.setText(item.name);
        tvCode.setText(item.code);

        ivAdd.setOnClickListener(v -> {
            ivAdd.setVisibility(View.GONE);
            tvAdd.setVisibility(View.VISIBLE);
            if (listener != null)
                listener.addStock();
        });
    }

    public interface OnOptionalStockAdapterListener{
        void addStock();
    }

}
